package com.wzh.project.redis.lettcue;

import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;

/**
*@author : 汪振海
*@createdDate : Mar 6, 2020  2:13:09 PM
*@description : <br>client
*
*/
public class LettcueClient {
	
	private StatefulRedisConnection<String, byte[]> connection=null;
	
	
	public void init() {
		RedisClient client = RedisClient.create("redis://172.16.5.18:6379");
		connection = client.connect(new Test());
		System.out.println("SUCC");
	}
	
	public void send(String msg) {
		if (connection==null) {
			init();
		}
		RedisCommands<String, byte[]> sync = connection.sync();
		int num=0;
		while(true) {
			num++;
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			sync.lpush("key", (msg+num).getBytes());
			System.out.println("SUCC push"+msg+num);
		}
		
		
	}
	
	public static void main(String[] args) {
		new LettcueClient().send("wzh");
	}

}
